package demo1222.pm;
/*
递归:方法自己调用自己
没有优点,只有缺点,占用大量的栈内存空间.
递归必须有结束的条件.

求1-5的和:1+2+3+4+5
递归的思想:5+4+3+2+1
 */
public class Demo_01 {
    public static void main(String[] args) {
        System.out.println(sum(5));
        System.out.println(tuZi(7));
    }
    /*
      num= 5     return 5+sum(4)
      num= 4     return 4+sum(3)
      num= 3     return 3+sum(2)
      num= 2     return 2+sum(1)
      num= 1     return 1;
     */
    public static int sum(int num){
        if (num ==1){
            return 1;
        }
        return num+sum(--num);
    }
/*
month 1    1
month 2    1
month 3    2
month 4    3
month 5    5
month 6    8
month 7    13
 */
    public  static int tuZi(int month){
        if (month==1||month==2){
            return 1;
        }
        return tuZi(month-1)+tuZi(month-2);
    }
}
